//
// Created by dqchen on 2022/11/2.
//

#include "meta.h"
#include <sstream>

Token::Token(Tag t):tag(t) {

}

string Token::toString() {
    return tags[tag];
}

Token::~Token() {
}

Id::Id(string name) : Token(ID), name(name) {

}

string Id::toString() {
    return Token::toString() + name;
}

Num::Num(int v) : Token(NUM), value(v) {

}

string Num::toString() {
    return Token::toString();
}

Str::Str(string s) : Token(STR), str(s) {

}
string Str::toString() {
    return string("[") + Token::toString() + "]:" + str;
}

Char::Char(char ch) : Token(CHAR) {
    this->ch = ch;
}

string Char::toString() {
    stringstream ss;
    ss << ch;
    return string("[") + Token::toString() + "]:" + ss.str();
}

Bol::Bol(int value) : Token(BOL) {
    this->bol = value;
}

string Bol::toString() {
    stringstream ss;
    ss << bol;
    return Token::toString() + ss.str();
}

Struct::Struct(std::string t): Token(STRUCT) {
    this->type = t;
}

string Struct::toString() {
    stringstream ss;
    ss << type;
    return Token::toString() + ss.str();
}

Keyword::Keyword() {
    keywords.insert(std::pair<string, Tag>("int", INT));
    keywords.insert(std::pair<string, Tag>("string", STR));
    keywords.insert(std::pair<string, Tag>("char", CHAR));
    keywords.insert(std::pair<string, Tag>("void", VOID));
    keywords.insert(std::pair<string, Tag>("return", RETURN));
    keywords.insert(std::pair<string, Tag>("struct", STRUCT));

}

class Token;